function Router() {
	this.cache = {};
	this.on = function(key, value) {
		var cache = this.cache;
		cache[key] = value;
	};
	//匹配hash对应的回调函数，并触发
	this.trigger = function(hash) {
		var cache = this.cache;
		for(var r in cache){
			var reg = this.initRegexps(r);
			if(reg.test(hash)) {
				var callback = cache[r] || function(){};
				var params = this.getParams(reg, hash);
				callback.apply(this, params);
			}
		}
	};
	//初始化 添加监听浏览器hashchange 以及dom loaded函数
    this.init = function () {
        window.addEventListener('hashchange', function () {
            var hash = location.hash.slice(1);
            router.trigger(hash);
        });
        window.addEventListener('load', function () {
            var hash = location.hash.slice(1) || 'default';
            router.trigger(hash);
        })
    };
    /**
     *将cache内的key 做正则处理,并返回
     * 第一个正则 匹配诸如/,.+-?$#{}[]] 关键字  并在关键字前面加转译字符\
     * 第二个正则 匹配() 标示()内部内容可有可无
     * 第三个正则 匹配: 在/后面可以由接受任意字符,直到遇到下一个/
     * 第四个正则 匹配* 在*后面可以由接受任意字符
     */
    this.initRegexps = function (route) {
        route = route.replace(/[/,.+\-?$#{}\[\]]/g, '\\$&')
            .replace(/\((.*?)\)/g, '(?:$1)?')
            .replace(/(\/\w?:\w+)+/g, '\/([^/]+)')
            .replace(/\*\w*/g, '([^?]*?)');

        return new RegExp('^' + route + '$');
    };
    //将匹配的正则返回,为回调函数提供参数
    this.getParams = function (reg, hash) {
        return reg.exec(hash).slice(1);
    }
}

var router = new Router();

//默认主页
router.on('/home', function() {
	getHome();
})
//登录
router.on('/login', function() {
	getLogin();
})
//注册
router.on('/reg', function() {
	reg();
})
//技术供给
router.on('/supply',function(){
	getMoreSupplyList(1,5,4,'moreSupplyList');
})

//技术供给详情
router.on('/supply/infoDetails/*', function(supplyId) {
	getSupplyInfoDetails(supplyId);
})
//技术需求
router.on('/require',function(){
	getMoreRequireList(1,5,4,'moreRequireList');
})
//技术需求详情
router.on('/require/infoDetails/*', function(requireId) {
	getRequireInfoDetails(requireId);
})
//会员信息
router.on('/memberInfo',function(){
	getMemberInfo();
	
})
//科研单位
router.on('/memberInfo/scientify', function() {
	getFiled(5,{id: 'scientify'});
})
//首页查询科研单位信息
router.on('/memberInfo/scientify/*', function(key) {
	getFiled(1,{id: 'scientify'}, key);
})
//科研单位详情
router.on('/memberInfo/scientify/infoDetails/*/*', function(userId, userType) {
	getSelect({name : userId}, userType);
})
//高校单位
router.on('/memberInfo/college', function() {
	getFiled(4, {id: 'college'});
})
//首页查询高校信息
router.on('/memberInfo/college/*', function(key) {
	getFiled(1,{id: 'college'}, key);
})
//科研单位详情
router.on('/memberInfo/college/infoDetails/*/*', function(userId, userType) {
	getSelect({name : userId}, userType);
})
//中介机构单位
router.on('/memberInfo/agency', function() {
	getFiled(3,{id: 'agency'});
})
//首页查询中介机构信息
router.on('/memberInfo/agency/*', function(key) {
	getFiled(1,{id: 'agency'}, key);
})
//中介单位详情
router.on('/memberInfo/agency/infoDetails/*', function(userId) {
	getAgencyDetailsForPublic({name: userId});
})
//企业单位
router.on('/memberInfo/company', function() {
	getFiled(2,{id: 'company'});
})
//首页查询企业信息
router.on('/memberInfo/company/*', function(key) {
	getFiled(1,{id: 'company'}, key);
})
//企业单位详情
router.on('/memberInfo/company/infoDetails/*', function(userId) {
	getCompanyDetailsForPublic({name: userId});
})
//个人会员
router.on('/memberInfo/person', function() {
	getFiled(1,{id: 'person'});
})
//首页查询个人会员信息
router.on('/memberInfo/person/*', function(key) {
	getFiled(1,{id: 'person'}, key);
})
//个人会员详情
router.on('/memberInfo/person/infoDetails/*', function(userId) {
	getPersonDetailsForPublic({name: userId});
})
//政策法规
router.on('/policyInfo',function(){
	getMoreInfoList(1,10,1,'morePolicyList');
})
//公告或政策详情
router.on('/home/infoDetails/*', function(infoId) {
	getInfoDetails(infoId);
})
//产品成果信息
router.on('/produceInfo',function(){
	getMoreProduceConditionFiled(1,5,'moreProduceList');
})

router.on('/produceInfo/infoDetails/*', function(produceId) {
	getProduceInfoDetails(produceId);
})
//通知公告
router.on('/moreNoticeInfo', function() {
	getMoreInfoList(1,5,2,'morePolicyList');
})
//通知公告
router.on('/morePolicyInfo', function() {
	getMoreInfoList(1,5,1,'morePolicyList');
})

router.init();